<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/20
 * Time: 15:17
 */

Class WxPaySign{

    /**
     * 设置签名，详见签名生成算法
     * @param string $value
     **/
    public function SetSign($params)
    {
        $key = config('base.WXKEY');
        //签名步骤一：按字典序排序参数
        ksort($params);

        $buff = "";
        foreach ($params as $k => $v)
        {
            if($k != "sign" && $v != "" && !is_array($v)){
                $buff .= $k . "=" . $v . "&";
            }
        }

        $string = trim($buff, "&");

        //签名步骤二：在string后加入KEY
        $string = $string . "&key=".$key;
        //签名步骤三：MD5加密
        $string = md5($string);
        //签名步骤四：所有字符转为大写
        $sign = strtoupper($string);

        return $sign;
    }
}